home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-addima.adb < prev    next >
Text File  |  1996-01-30  |  3KB  |  54 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --                  S Y S T E M . A D D R E S S _ I M A G E                 --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.4 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with Unchecked_Conversion;
  27.  
  28. function System.Address_Image (A : Address) return String is
  29.  
  30.    Result  : String (1 .. 2 * Address'Size / Storage_Unit);
  31.  
  32.    type Byte is mod 2 ** 8;
  33.    for Byte'Size use 8;
  34.  
  35.    Hexdigs :
  36.      constant array (Byte range 0 .. 15) of Character := "0123456789ABCDEF";
  37.  
  38.    type Bytes is array (1 .. Address'Size / Storage_Unit) of Byte;
  39.    for Bytes'Size use Address'Size;
  40.  
  41.    function To_Bytes is new Unchecked_Conversion (Address, Bytes);
  42.  
  43.    Byte_Sequence : constant Bytes := To_Bytes (A);
  44.  
  45. begin
  46.    for N in Bytes'Range loop
  47.       Result (2 * N - 1) := Hexdigs (Byte_Sequence (N) / 16);
  48.       Result (2 * N)     := Hexdigs (Byte_Sequence (N) mod 16);
  49.    end loop;
  50.  
  51.    return Result;
  52.  
  53. end System.Address_Image;
  54.